package AccessDB;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class CalendarioDAO {
	
	private Connection con;
	
	public CalendarioDAO()
	{
		super();
		this.con = ConnectionDB.getInstance().getConnection();
	}
	
	public boolean inserirCalendario(String caminho, int ano) throws SQLException
	{
		
		PreparedStatement stmt = con.prepareStatement("insert into Calendario values(?,?)");
		stmt.setInt(1, ano);
		stmt.setString(2, caminho);
		
		stmt.executeUpdate();
		
		return true;
		
	}
	
	public String retornaUltimoCalendarioDoAno(int ano) throws SQLException
	{
		
		PreparedStatement stmt = con.prepareStatement("select caminho from Calendario where idCalendario = (select MAX(idCalendario) from Calendario where ano = ?)");
		stmt.setInt(1, ano);
		
		ResultSet rs = stmt.executeQuery();
		
		if(rs.next())
			return rs.getString("caminho");
		
		return null;
		
	}
	
}